package com.yuanduan.mplus.presenter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuanduan.mplus.R;
import com.yuanduan.mplus.model.entity.DriveAnalyseEntity;
import com.yuanduan.mplus.view.DriveAnalyseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cj on 2016/6/22.
 * Email:781806481@qq.com
 */
public class DriveAnalyseAdapter extends BaseAdapter {
    private Context mContext;
    private List<DriveAnalyseEntity> datas=new ArrayList<>();
    public DriveAnalyseAdapter(Context context) {
        mContext=context;
    }

    public void setDatas(List<DriveAnalyseEntity> lists){
        datas=lists;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {

        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DriveAnalyseEntity entity=datas.get(position);
        View view ;
        ViewHolder holder;
        if(convertView==null){
            view= LayoutInflater.from(mContext).inflate(R.layout.driveanalyse_listview,null);
            holder=new ViewHolder();
            holder.tv1= (TextView) view.findViewById(R.id.driveanalyse_tv1);
            holder.tv2= (TextView) view.findViewById(R.id.driveanalyse_tv2);
            holder.tv3= (TextView) view.findViewById(R.id.driveanalyse_tv3);
            holder.tv4= (TextView) view.findViewById(R.id.driveanalyse_tv4);
            holder.tv5= (TextView) view.findViewById(R.id.driveanalyse_tv5);
            view.setTag(holder);
        }else{
            view=convertView;
            holder= (ViewHolder) view.getTag();
        }
        if (position%2==0){
            view.setBackgroundResource(R.color.light_gray);
        }
        if (entity.getLevel()==3){
            holder.tv1.setTextColor(mContext.getResources().getColor(android.R.color.holo_green_dark));

        }else if(entity.getLevel()==2){
            holder.tv1.setTextColor(mContext.getResources().getColor(android.R.color.holo_red_light));
        }

        holder.tv1.setText(entity.getUserName());
        holder.tv2.setText(entity.getSafeScore()+"");
        holder.tv3.setText(entity.getEconomicalScore()+"");
        holder.tv4.setText(entity.getTime());
        holder.tv5.setText(entity.getDistance());
        return view;
    }

    class ViewHolder{
        private TextView tv1;
        private TextView tv2;
        private TextView tv3;
        private TextView tv4;
        private TextView tv5;
    }
}
